<template>
  <Lazy :isLoading="isLoading" :finish="finish" @lazyHtppHandle="getTalk">
    <el-timeline class="timeLine">
      <el-timeline-item
        class="itemTime"
        color="#49b1f5"
        :hollow="true"
        :timestamp="dayjs(item.createTime - 0).format('YYYY-MM-DD HH:mm')"
        placement="top"
        v-for="item in store.state.talkList"
        :key="item._id"
      >
        <el-card>
          <el-row>
            <el-col :span="2">
              <div class="avatar">
                <el-avatar
                  :src="
                    store.state.BaseUrl +
                      store.state.centerData[1].adminAvatar ||
                    `https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png`
                  "
                  :size="50"
                >
                </el-avatar>
              </div>
            </el-col>
            <el-col :span="21">
              <h4 class="username">{{ item.username }}</h4>
              <p class="info">{{ item.talk }}</p>
              <p class="createTime">
                {{ dayjs(item.createTime - 0).format('YYYY-MM-DD HH:mm') }}
              </p>
            </el-col>
          </el-row>
        </el-card>
      </el-timeline-item>
    </el-timeline>
  </Lazy>
</template>
<script lang="ts" setup>
import { ref, inject, nextTick } from 'vue'
import { getTalkHttp } from '@/utils/http/talkHttp'
import Lazy from '../global/Lazy.vue'
import dayjs from 'dayjs'
// 是否正在加载
const isLoading = ref<boolean>(false)
// 是否加载完成
const finish = ref<boolean>(false)
// 导入lazy组件
const store: any = inject('store')
let page = store.state.talkList.length ? 2 : 1

const getTalk = async () => {
  isLoading.value = true
  let res = await getTalkHttp(page++)
  store.postTalk(res.data.info.data, res.data.info.num)
  finish.value = store.state.talkNum <= store.state.talkList.length
  nextTick(() => {
    isLoading.value = false
  })
}
!store.state.talkList.length && getTalk()
</script>
<style lang="scss">
.el-card.is-always-shadow {
  border-radius: 15px;
}
.el-timeline-item__tail {
  border-left: 2px solid #fff;
  font-size: 14px;
}
.itemTime {
  transition: all 0.5s;
  &:hover {
    transform: translateY(-3px);
  }
}

.el-timeline-item__timestamp {
  color: #49b1f5 !important;
}
.el-timeline-item__node.el-timeline-item__node--normal {
  left: 0 !important;
}
</style>
<style lang="scss" scoped>
.timeLine {
  margin: 40px auto;
  max-width: 1000px;
}
.info {
  width: 100%;
  overflow: auto;
  margin: 20px 0 13px;
  font-size: 16px;
}
.createTime {
  color: #999;
  font-size: 12px;
}
.username {
  font-weight: 700;
  font-size: 16px;
  font-weight: 900;
}

@media (max-width: 760px) {
  .timeLine {
    margin-right: 10px;
  }
  .info {
    margin-left: 40px;
    margin-top: 10px;
  }
  .username {
    margin-left: 40px;
  }
  .createTime {
    margin-left: 40px;
  }
}
</style>
